﻿
#region 程序集引用区
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using SubSonic.DataProviders;
using SubSonic.Extensions;
using System.Linq.Expressions;
using SubSonic.Schema;
using System.Collections;
using SubSonic;
using SubSonic.Repository;
using System.ComponentModel;
using System.Data.Common;
using SubSonic.Query;
using System.Xml;
using System.Xml.Serialization;
using System.Reflection;

//引用实体层
using WebeTerm.Model;
using WebeTerm.Common;
#endregion

namespace WebeTerm.DbProvider{
    /// <summary>
    /// 文 件 名: EmployeeInfoDAL.cs
    /// CLR版本 : v2.0.50727
    /// 作   者 : lijun.hu
    /// 版    权: Copyright @2011 lijun.hu(FORCEN HU) 
    /// 电子邮箱：lijun.hu@shinsoft.net
    /// 说    明: 员工信息
    /// 生成日期: 2014年12月5日
    /// </summary>
    public partial class EmployeeInfoDAL:BaseDAL< EmployeeInfo >{
        
        #region 通用查询
        /// <summary>
        /// 查询系统设置
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="pages">分页信息</param>
        /// <returns>系统设置</returns>
        public List< EmployeeInfo > SearchEmployeeInfo(EmployeeInfoQuery queryParam, Pages pages)
        {
            IQueryable< EmployeeInfo > iQuery = QueryEmployeeInfo(queryParam);
            var items = base.SplitPage(iQuery, pages).ToList();
            items.ForEach(l=>{
                { if (l is IModel) { (l as IModel).SetIsLoaded(); } }    
            });
            return items;
        }

        /// <summary>
        /// 计算系统设置数
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <returns>系统设置数</returns>
        public int SearchEmployeeInfoCount(EmployeeInfoQuery queryParam)
        {
            return QueryEmployeeInfo(queryParam).Count();
        } 
        #endregion

        #region 组合查询
        /// <summary>
        /// 设置 员工信息 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <returns>员工信息</returns>
        public IQueryable< EmployeeInfo > QueryEmployeeInfo(EmployeeInfoQuery queryParam)
        {
            IQueryable<EmployeeInfo> iQuery = All();
            iQuery = QueryEmployeeInfoById(queryParam, iQuery);
            iQuery = QueryEmployeeInfoByEmployeeNo(queryParam, iQuery);
            iQuery = QueryEmployeeInfoByEmployeeName(queryParam, iQuery);
            iQuery = QueryEmployeeInfoByPassword(queryParam, iQuery);
            iQuery = QueryEmployeeInfoByExpireDate(queryParam, iQuery);
            iQuery = QueryEmployeeInfoByCompanyId(queryParam, iQuery);
            iQuery = QueryEmployeeInfoByEmployeeFlag(queryParam, iQuery);
            iQuery = QueryEmployeeInfoByEmail(queryParam, iQuery);
            iQuery = QueryEmployeeInfoByQQ(queryParam, iQuery);
            iQuery = QueryEmployeeInfoByWeiXinNo(queryParam, iQuery);
            iQuery = QueryEmployeeInfoByReceiveType(queryParam, iQuery);
            return iQuery;
        }
        #endregion
        
        #region 单条件查询
        /// <summary>
        /// 根据设置 员工信息 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">员工信息 查询</param>
        /// <returns>员工信息 查询</returns>
        protected virtual IQueryable< EmployeeInfo > QueryEmployeeInfoById(EmployeeInfoQuery queryParam, IQueryable< EmployeeInfo > iQuery)
        {
            if (queryParam.Id != Guid.Empty)
                iQuery = iQuery.Where(iq => iq.Id == queryParam.Id);
            return iQuery;
        }
        /// <summary>
        /// 根据设置 员工信息 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">员工信息 查询</param>
        /// <returns>员工信息 查询</returns>
        protected virtual IQueryable< EmployeeInfo > QueryEmployeeInfoByEmployeeNo(EmployeeInfoQuery queryParam, IQueryable< EmployeeInfo > iQuery)
        {
            if (!string.IsNullOrEmpty(queryParam.EmployeeNo))
                iQuery = iQuery.Where(iq => iq.EmployeeNo.Contains(queryParam.EmployeeNo.Trim()));
            return iQuery;
        }
        /// <summary>
        /// 根据设置 员工信息 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">员工信息 查询</param>
        /// <returns>员工信息 查询</returns>
        protected virtual IQueryable< EmployeeInfo > QueryEmployeeInfoByEmployeeName(EmployeeInfoQuery queryParam, IQueryable< EmployeeInfo > iQuery)
        {
            if (!string.IsNullOrEmpty(queryParam.EmployeeName))
                iQuery = iQuery.Where(iq => iq.EmployeeName.Contains(queryParam.EmployeeName.Trim()));
            return iQuery;
        }
        /// <summary>
        /// 根据设置 员工信息 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">员工信息 查询</param>
        /// <returns>员工信息 查询</returns>
        protected virtual IQueryable< EmployeeInfo > QueryEmployeeInfoByPassword(EmployeeInfoQuery queryParam, IQueryable< EmployeeInfo > iQuery)
        {
            if (!string.IsNullOrEmpty(queryParam.Password))
                iQuery = iQuery.Where(iq => iq.Password.Contains(queryParam.Password.Trim()));
            return iQuery;
        }
        /// <summary>
        /// 根据设置 员工信息 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">员工信息 查询</param>
        /// <returns>员工信息 查询</returns>
        protected virtual IQueryable< EmployeeInfo > QueryEmployeeInfoByExpireDate(EmployeeInfoQuery queryParam, IQueryable< EmployeeInfo > iQuery)
        {
            if (queryParam.ExpireDate != DateTime.MinValue)
                iQuery = iQuery.Where(iq => iq.ExpireDate == queryParam.ExpireDate);
            return iQuery;
        }
        /// <summary>
        /// 根据设置 员工信息 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">员工信息 查询</param>
        /// <returns>员工信息 查询</returns>
        protected virtual IQueryable< EmployeeInfo > QueryEmployeeInfoByCompanyId(EmployeeInfoQuery queryParam, IQueryable< EmployeeInfo > iQuery)
        {
            if (queryParam.CompanyId != Guid.Empty)
                iQuery = iQuery.Where(iq => iq.CompanyId == queryParam.CompanyId);
            return iQuery;
        }
        /// <summary>
        /// 根据设置 员工信息 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">员工信息 查询</param>
        /// <returns>员工信息 查询</returns>
        protected virtual IQueryable< EmployeeInfo > QueryEmployeeInfoByEmployeeFlag(EmployeeInfoQuery queryParam, IQueryable< EmployeeInfo > iQuery)
        {
            if (!string.IsNullOrEmpty(queryParam.EmployeeFlag))
                iQuery = iQuery.Where(iq => iq.EmployeeFlag.Contains(queryParam.EmployeeFlag.Trim()));
            return iQuery;
        }
        /// <summary>
        /// 根据设置 员工信息 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">员工信息 查询</param>
        /// <returns>员工信息 查询</returns>
        protected virtual IQueryable< EmployeeInfo > QueryEmployeeInfoByEmail(EmployeeInfoQuery queryParam, IQueryable< EmployeeInfo > iQuery)
        {
            if (!string.IsNullOrEmpty(queryParam.Email))
                iQuery = iQuery.Where(iq => iq.Email.Contains(queryParam.Email.Trim()));
            return iQuery;
        }
        /// <summary>
        /// 根据设置 员工信息 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">员工信息 查询</param>
        /// <returns>员工信息 查询</returns>
        protected virtual IQueryable< EmployeeInfo > QueryEmployeeInfoByQQ(EmployeeInfoQuery queryParam, IQueryable< EmployeeInfo > iQuery)
        {
            if (!string.IsNullOrEmpty(queryParam.QQ))
                iQuery = iQuery.Where(iq => iq.QQ.Contains(queryParam.QQ.Trim()));
            return iQuery;
        }
        /// <summary>
        /// 根据设置 员工信息 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">员工信息 查询</param>
        /// <returns>员工信息 查询</returns>
        protected virtual IQueryable< EmployeeInfo > QueryEmployeeInfoByWeiXinNo(EmployeeInfoQuery queryParam, IQueryable< EmployeeInfo > iQuery)
        {
            if (!string.IsNullOrEmpty(queryParam.WeiXinNo))
                iQuery = iQuery.Where(iq => iq.WeiXinNo.Contains(queryParam.WeiXinNo.Trim()));
            return iQuery;
        }
        /// <summary>
        /// 根据设置 员工信息 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">员工信息 查询</param>
        /// <returns>员工信息 查询</returns>
        protected virtual IQueryable< EmployeeInfo > QueryEmployeeInfoByReceiveType(EmployeeInfoQuery queryParam, IQueryable< EmployeeInfo > iQuery)
        {
            if (queryParam.ReceiveType != (int)0)
                iQuery = iQuery.Where(iq => iq.ReceiveType == queryParam.ReceiveType);
            return iQuery;
        }
        #endregion
    }
}    